﻿using System.Collections.Generic;
using UtilZ.Dotnet.Ex.Attributes;
using UtilZ.Dotnet.Ex.ValueDescription;

namespace UtilZ.Dotnet.Ex.Model
{
    /// <summary>
    /// 异常HResult值常量定义类
    /// </summary>
    public class HResultConstant
    {
        private readonly static ValueDescriptionGroup<int> _group = null;
        static HResultConstant()
        {
            _group = new ValueDescriptionGroup<int>(typeof(HResultConstant), nameof(HResultConstant));
        }



        /// <summary>
        /// 获取项列表
        /// </summary>
        /// <returns>项列表</returns>
        public static List<NameValue<int>> GetValueItemList()
        {
            var list = new List<NameValue<int>>();
            foreach (ConstantValueItem item in _group)
            {
                list.Add(new NameValue<int>(item.DisplayName, (int)item.Value));
            }
            return list;
        }

        /// <summary>
        /// 获取名称
        /// </summary>
        /// <param name="value">值</param>
        /// <returns>名称</returns>
        public static string GetName(int value)
        {
            string name;
            if (_group.TryGetNameByValue(value, out name))
            {
                return name;
            }
            else
            {
                return $"未知值\"{value}\"";
            }
        }

        /// <summary>
        /// 获取详情描述说明
        /// </summary>
        /// <param name="value">值</param>
        /// <returns>名称</returns>
        public static string GetDescription(int value)
        {
            string name;
            if (_group.TryGetDescriptionByValue(value, out name))
            {
                return name;
            }
            else
            {
                return $"未知值\"{value}\"";
            }
        }







        /// <summary>
        /// 文件被其它程序打开占用
        /// </summary>
        [DisplayNameEx("文件被占用", "另一个程序正在使用此文件，进程无法访问。")]
        public static int FILE_ANOTHER_PROCESS_USE = -2147024864;

        /// <summary>
        /// 文件不存在
        /// </summary>
        [DisplayNameEx("文件不存在", "系统找不到指定的文件。")]
        public static int FILE_NOT_EXIT = -2147024894;
    }
}
